package tenantchannellogic

import (
	"context"
	tenantChannel "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	schema "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ThirdpartyBankCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewThirdpartyBankCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ThirdpartyBankCreateLogic {
	return &ThirdpartyBankCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// ThirdpartyBankCreate 三方银行
func (l *ThirdpartyBankCreateLogic) ThirdpartyBankCreate(in *rpc.ThirdpartyBankCreateRequest) (*rpc.TenantCommonResponse, error) {
	var CommonResp rpc.CommonResp
	thirdpartyBank := &schema.TenantChannelThirdpartyBank{
		BankCode:  in.BankCode,
		BankName:  in.BankName,
		AgentName: in.AgentName,
		Status:    in.Status,
		Sort:      in.Sort,
	}
	err := tenantChannel.NewTenantChannelThirdpartyBankModel(l.ctx, l.svcCtx.Db).CreateThirdpartyBank(thirdpartyBank)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.TenantCommonResponse{
			CommonResp: &CommonResp,
		}, err
	}
	CommonResp.Message = "Success"
	return &rpc.TenantCommonResponse{
		CommonResp: &CommonResp,
	}, nil
}
